﻿/*
 * Copyright (C) 2010 Jakub Miara
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Net.Araim.FavouriteLocations
{
    [Serializable]
    public class FavouriteLocation
    {
        public string Name { get; set; }
        public string Path { get; set; }

        public FavouriteLocation()
        {
            this.Name = string.Empty;
            this.Path = string.Empty;

        }
        public override bool Equals(object obj)
        {
            if (obj == null) { return false; }
            if (obj is FavouriteLocation)
            {
                return Name == (obj as FavouriteLocation).Name;
            }
            return base.Equals(obj);
        }
    }

    public class FavouriteLocationComparer : IEqualityComparer<FavouriteLocation>, IComparer<FavouriteLocation>
    {

        public bool Equals(FavouriteLocation x, FavouriteLocation y)
        {
            return (x.Name == y.Name);
        }

        public int GetHashCode(FavouriteLocation obj)
        {
            return obj.Name.GetHashCode();
        }

        public int Compare(FavouriteLocation x, FavouriteLocation y)
        {
            if (x != null && y != null)
            {
                int c = x.Name.CompareTo(y.Name);
                if (c != 0) { return c; }
                else { return x.Path.CompareTo(y.Path); }
            }
            else if (y != null) { return -1; }
            else if (x != null) { return 1; }
            else { return 0; }
        }
    }
}
